package top.milkbox.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.milkbox.domain.PostComment;
import top.milkbox.info.R;
import top.milkbox.service.PostCommentService;

@RestController
@RequestMapping("/postComments")
public class PostCommentController {

    @Autowired
    private PostCommentService postCommentService;

    @PostMapping("/add.login")
    public R add(
            @CookieValue("token") String token,
            @RequestBody PostComment postComment
    ) {
        R r = new R();
        boolean isSuccess = postCommentService.addComment(
                token, postComment.getPostId(), postComment.getContent());
        r.setFlag(isSuccess);
        if (isSuccess) {
            r.setMessage("评论发布成功");
        } else {
            r.setMessage("评论发布失败");
        }

        return r;
    }
}
